package com.hwd.gmall.order.listener;

import com.hwd.gmall.common.aspect.ListenMessage;
import com.hwd.gmall.common.constant.PaymentConst;
import com.hwd.gmall.order.service.OrderService;
import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 监听订单支付结果的消费者
 *
 * @author 黄伟东/Victor
 * @date 2022/5/10 23:21
 */
@Component
@Log4j2
public class OrderPayListener {

    @Resource
    private OrderService orderService;

    /**
     * 监听订单支付结果的消息
     *
     * @param message 消息体
     * @param ignoredChannel 连接
     */
    @RabbitListener(queues = PaymentConst.ORDER_PAY_QUEUE)
    @ListenMessage(messageDescription = "订单支付结果的消息")
    public void getOrderPayResult(Message message, Channel ignoredChannel) {
        // 修改订单的支付状态
        orderService.updateOrderStatus(new String(message.getBody()));
    }
}
